package com.ikkong.biz.meta.intercept;

import java.util.List;
import java.util.Map;

import com.ikkong.biz.service.TeacherService;
import com.ikkong.biz.service.impl.TeacherServiceImpl;
import com.ikkong.core.aop.AopContext;
import com.ikkong.core.dao.Db;
import com.ikkong.core.meta.PageIntercept;
import com.ikkong.core.toolbox.Conver;
import com.ikkong.core.toolbox.Func;
import com.ikkong.core.toolbox.Record;
import com.ikkong.core.toolbox.support.BladePage;

public class ClassesIntercept extends PageIntercept {
    TeacherService service = new TeacherServiceImpl();
	/**
	 * 查询后附加字典项
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void queryAfter(AopContext ac) {
		BladePage<Map<String, Object>> page = (BladePage<Map<String, Object>>) ac.getObject();
		List<Map<String, Object>> list = page.getRows();
		for (Map<String, Object> map : list) {
			map.put("dict_grade_id", Func.getDictName(1001, map.get("grade_id")));
            map.put("head_teacher_name", service.getHeadTeacherName(map.get("head_teacher")));
            map.put("subject_teacher_names",service.getSubjectTeacherNames(Conver.toStr(map.get("teachers"),"")));
            int count = Db.init().queryInt("select count(1) from tb_student where class_id = #{classid}", Record.create().set("classid",map.get("id")));
            map.put("stu_count",count);
            String fullName = map.get("graduate_year") + "届"+Func.getDictName(1001, map.get("grade_id"))+map.get("class_name");
            map.put("full_class_name",fullName);
        }
	}
	
}
